
-- 浅拷贝
table.clone = function(t, nometa)
    local result = {}
    if not nometa then
        setmetatable(result, getmetatable(t))
    end
    for k, v in pairs (t) do
        result[k] = v
    end
    return result
end

-- 深拷贝
table.copy = function(t, nometa)
    local result = {}

    if not nometa then
        setmetatable(result, getmetatable(t))
    end

    for k, v in pairs(t) do
        if type(v) == "table" then
            result[k] = table.copy(v)
        else
            result[k] = v
        end
    end
    return result
end

--取子数组
table.sub = function(arr,star,n)
    local len = #arr
    if not n then 
    	n = len
    end

    if len < n or len < star then 
        return {}
    end
    local tb = {}
    for i = star, n do
        table.insert(tb,arr[i])
    end    
    return tb
end


table.removeSub = function(tb,tbSub)
    if not tbSub or not next(tbSub) then 
        return
    end
    local tbRemove = {}
    local tb2 = table.copy(tb)
    for k,v in pairs(tb2) do 
        for _,card in pairs(tbSub) do 
            if v == card then 
                table.insert(tbRemove,k)
            end
        end
    end
    local function sort(a,b)
        return a>b
    end 
    table.sort(tbRemove,sort)
    for k,v in pairs(tbRemove) do 
        table.remove(tb2,v)
    end    
    return tb2
end

--取剩余的数据
table.subRest = function(arr,star,n)
    local len = #arr
    if not n then 
        n = len
    end
    local tb = {}
    for i=1, star-1 do
        table.insert(tb,arr[i])
    end
    for i=star+n,len do 
        table.insert(tb,arr[i])    
    end
    return tb
end

--连接 
table.concatList = function (tb1,tb2)
	if type(tb1)~='table' or type(tb2) ~='table' then 
		return
	end
    for _,v in pairs(tb2) do 
        table.insert(tb1,v)
    end
end

function handler(obj, method)
    return function(...)
        return method(obj, ...)
    end
end

function class(classname, super)
	local superType = type(super)
	local cls
	if superType ~= 'function' and superType ~= 'table' then
		superType = nil
		super = nil
	end

	if superType == 'function' or (super and super.__ctype == 1) then
		-- inherited from native C++ Object
		cls = {}
		if superType == 'table' then
			-- copy fields from super
			for k,v in pairs(super) do cls[k] = v end
			cls.__create = super.__create
			cls.super = super
		else
			cls.__create = super
			cls.ctor = function() end
		end
		cls.__cname = classname
		cls.__ctype = 1

		function cls.new(...)
			local instance = cls.__create(...)
			-- copy fields from class to  native object
			for k, v in pairs(cls) do instance[k] = v end
			instance.class = cls
			instance:ctor(...)
			return instance
		end
                cls.New = cls.new
	else
		-- inherited from Lua Object
		if super then
			cls = {}
			setmetatable(cls, {__index = super})
			cls.super = super
		else
			cls = {ctor = function() end}
		end
		cls.__cname = classname
		cls.__ctype = 2 --lua
		cls.__index = cls

		function cls.new(...)
			local instance = setmetatable({}, cls)
			instance.class = cls
			instance:ctor(...)
			return instance
		end
                cls.New = cls.new
	end
	return cls
end


---不会死循环的dump
function dump(tab, _tostring)
    _tostring = _tostring and _tostring or tostring

    local function getkey(k, ktype)
        if ktype == 'number' then
            return '[' .. k .. ']'
        elseif ktype == 'string' then
            return '["' .. k .. '"]'
        else
            return '[' .. _tostring(k) .. ']'  --key可能是table
        end
    end

    local tinsert = table.insert
    local mmax = math.max
    local rep = string.rep
    local gsub = string.gsub
    local format = string.format

    local function dump_obj(obj, key, sp, lv, st)
        local sp = '\t'

        if type(obj) ~= 'table' then
            return sp .. (key or '') .. ' = ' .. tostring(obj) .. '\n'
        end

        local ks, vs, s= { mxl = 0 }, {}
        lv, st =  lv or 1, st or {}

        st[obj] = key or '.' --table对象列表
        key = key or ''
        for k, v in pairs(obj) do
            local ktype, vtype = type(k), type(v)
            if k ~= 'class' and k ~= '__index' and vtype ~= 'function'then
                if vtype == 'table' then
                    if st[v] then --相互引用的table，直接输出
                        vs[#vs + 1] = '[' .. st[v] .. ']'
                        s = sp:rep(lv) .. getkey(k, ktype)
                        tinsert(ks, s)
                        ks.mxl = mmax(#s, ks.mxl)
                    else
                        st[v] = key .. '.' .. _tostring(k) --保存dump过的table，key可能也是table
                        vs[#vs + 1] = dump_obj(v, st[v], sp, lv + 1, st)
                        s = sp:rep(lv) .. getkey(k, ktype)
                        tinsert(ks, s)
                        ks.mxl = mmax(#s, ks.mxl)
                    end
                else
                    if vtype == 'string' then
                        vs[#vs + 1] = (('%q'):format(v):gsub('\\\10','\\n'):gsub('\\r\\n', '\\n'))
                    else
                        vs[#vs + 1] = tostring(v)
                    end
                    s = sp:rep(lv) .. getkey(k, ktype)
                    tinsert(ks, s)
                    ks.mxl = mmax(#s, ks.mxl);
                end
            end
        end

        s = ks.mxl
        for i, v in ipairs(ks) do
            vs[i] = v .. (' '):rep(s - #v) .. ' = ' .. vs[i] .. '\n'
        end

        return '{\n' .. table.concat(vs) .. sp:rep(lv-1) .. '}'
    end

    return dump_obj(tab)
end

----------------------------------


local random = math.random
local floor = math.floor
local Rule = class("Rule")


function  Rule:ctor()
	--随机种子
	math.randomseed(os.time())
	--扑克牌说明，0xAB, (A为花色 0黑桃 1红心 2草花 3方块)，B为点数1-13为A-K 
	-- self.card = {
	-- 	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
 --     	0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
 --     	0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
 --     	0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d
	-- }
	--牌 A=14,2=15,小王=160,大王=170
	self.card1 = {
		31,41,51,61,71,81,91,101,111,121,131,
		32,42,52,62,72,82,92,102,112,122,132,
		33,43,53,63,73,83,93,103,113,123,133,
		34,44,54,64,74,84,94,104,114,124,144,154,
	}
	self.card2 = {
		31,41,51,61,71,81,91,101,111,121,131,141,151,
		32,42,52,62,72,82,92,102,112,122,132,142,152,
		33,43,53,63,73,83,93,103,113,123,133,143,153,
		34,44,54,64,74,84,94,104,114,124,134,144,154,160,170
	}	
	self.card = self.card1
	--要发的牌
	self.tbCard = {}
	self.cardPairs = 1	--有几副牌
	self.ignoreCard = {160,170,141,142,143} --忽略的牌
	--牌型
  	self.cardType = {
	  	danZhang 	= 1, --单张
	  	duiZi 		= 2,
	  	sanZhang 	= 3,
	  	sanDaiYi 	= 4,	  	
	  	sanDaiEr 	= 5,
	  	liangDui 	= 6,	  	
	  	shunZi 		= 7,
	  	zhaDan 		= 8,
	  	siDaiN    	= 9,
	  	feiJi   	= 10,

	  	-- wangZha 	= 12,
	}
		
			
end

--洗牌
function Rule:shuffle()	
	self.tbCard = {}
	for _, v in pairs(self.card) do 
		table.insert(self.tbCard, v)
	end
	table.mix(self.tbCard)
end

--取牌值
function Rule:getCardNum(card)
	if not card then return nil end
	return floor(card / 10)
end

--取牌色
function Rule:getCardColor(card)
	return card % 10
end

--取牌
function Rule:getPlayAndBankCards()	

end

--输出牌型
function Rule:printCardType(cardType)
	for k,v in pairs(self.cardType) do 
		if v == cardType then 
			print("牌型"..k)
			return
		end
	end
end
--对牌排序
function Rule:sortCards(tbCard)
	local n1,n2
	local c1,c2
	local function sortFun(a,b)
		n1 = self:getCardNum(a)
		n2 = self:getCardNum(b)
		c1 = self:getCardColor(a)
		c2 = self:getCardColor(b)
		if n1 > n2 then 
			return true
		elseif n1 == n2 then 
			if c1 > c2 then 
				return true
			end
		end
		return false
	end
	table.sort(tbCard,sortFun)	
end

--取出所有连张
--num 连牌数
function Rule:getAllSame(tbCard,num)
	self:sortCards(tbCard)
	-- print("__getAllSame__",dump(tbCard))
	local len = #tbCard
	local tbRes = {}
	local tb = {}
	local num1 
	local num2 
	local n = 0
	for i=1,len-1 do 
		if not num1 then
			num1 = self:getCardNum(tbCard[i])
			table.insert(tb,tbCard[i])
		end
		num2 = self:getCardNum(tbCard[i+1])
		if num1 == num2 then 
			n = n + 1
			table.insert(tb,tbCard[i+1])
		else
			tb = {}
			num1 = nil
			n = 0
		end
		if n == num-1 then 			
			table.insert(tbRes,tb)
			tb = {}
			n = 0
			num1 = nil
		end
	end	
	return tbRes
end
------------------牌特征码
--[[
  根据一组合法牌计算特征值，用来比较大小
  特征值结构为
  【牌型大类（两位） | 节数（两位） | 牌值（三位）| 预留一位（默认4,为1则代表包含癞子）】
  比如55566637特征值为31 02 005 0。31表示三顺带单，02表示两节（从5到6），005是取最小那节的牌值，4是默认值。

  牌型代码和例子：
  单张。1。单张A2K的值依次是1 01 014 4，1 01 015 4，1 01 013 4。
  对子。2。对7 = 2 01 007 4。
  三条。3。三个5 = 3 01 005 4。
  三带单。4。5557 = 4 01 005 4。
  三带对。5。55577 = 5 01 005 4。
  四带两单。8。555579 = 8 01 005 4。
  四带两对。9。55557799 = 9 01 005 4。

  单顺。21。456789 = 21 06 004 4。
  双顺。22。556677 = 22 03 005 4。
  三顺。23
  三顺带单。飞机。24。66677735 = 24 02 006 4。
  三顺带对。飞机。25

  四条。炸弹。41。JJJJ = 41 01 011 4。
  双王。火箭。51。大小王 = 51 01 000 4。
]]
function Rule:calculateValue(a, b, c, fix)
  local fixValue = fix or 4
  return a * 1000000 + b * 10000 + c * 10 + fixValue
end

-- 分解特征值
function Rule:explodeValue(value)
  local a, b, c
  a, value =  math.modf(value / 1000000)
  value = value * 100000
  b, value = math.modf(value  / 1000)
  value = value * 1000
  c = math.modf(value)
  return a, b, c
end


--客户端需要的一个值
function Rule:getCardCode(tbCard,cardType)
  	local codeType = {
	  	danZhang 	= 1, --单张
	  	duiZi 		= 2,
	  	sanZhang 	= 3,
	  	sanDaiYi    = 4,
	  	sanDaiEr 	= 5,
	  	siDaiN    	= 8,
	  	liangDui 	= 22,
	  	feiJi       = 24,
	  	shunZi 		= 21,
	  	zhaDan 		= 41,
	}
	local codeNum,minCard
	local len = #tbCard
	local a,b,c
	local fix = 4
	b = 1
	c = self:getCardNum(tbCard[1])
	if not cardType then 
		cardType,minCard = self:getCardType(tbCard)
	end
	-- print("_____cardType__",cardType,minCard)
	if cardType == self.cardType.danZhang then 
		a = codeType.danZhang		
	elseif cardType == self.cardType.duiZi then
		a = codeType.duiZi
	elseif cardType == self.cardType.sanZhang then		
		a = codeType.sanZhang
	elseif cardType == self.cardType.siDaiN then		
		a = codeType.siDaiN	
		c = minCard
	elseif cardType == self.cardType.sanDaiYi then 	
		a = codeType.sanDaiYi	
		c = minCard	
 	elseif cardType == self.cardType.sanDaiEr then		
		a = codeType.sanDaiEr	
		c = minCard	 
	elseif cardType == self.cardType.liangDui then	
		a = codeType.liangDui
		b = floor(len/2)
		c = self:getCardNum(tbCard[len])		
	elseif cardType == self.cardType.shunZi then
		a = codeType.shunZi
		b = len
		c = self:getCardNum(tbCard[len])			
	elseif cardType == self.cardType.zhaDan then
		a = codeType.zhaDan			
	elseif cardType == self.cardType.feiJi then
		a = codeType.feiJi		
		b = floor(len/3)	
		c = minCard		
	end
	if a then 
		print("____(a,b,c,fix)__",a,b,c,fix)
		codeNum = self:calculateValue(a,b,c,fix)
	end
	print("___codeNum___",codeNum)
	return codeNum
end

------------------牌型
--单张
function Rule:isDanZhang(tbCard)
	if #tbCard == 1 then 
		return true
	end
	return false
end

--对子 
function Rule:isDuizi(tbCard)
	if #tbCard ~= 2 then 
		return false
	end

	for k, v in ipairs(tbCard) do
		for j = k + 1, #tbCard do			
			if self:getCardNum(tbCard[k]) == self:getCardNum(tbCard[j]) then
				return true
			end
		end
	end
	return false
end

--连对
function Rule:isLiangDui(tbCard)	
	local len = #tbCard
	if len < 4 or len%2 ~= 0 then 
		return false
	end
	self:sortCards(tbCard)
	local tb = self:getAllSame(tbCard,2)
	if #tb ~= len/2 then 
		return false
	end
	for i=1, #tb-1, 1 do
		if self:getCardNum(tb[i][1]) ~= self:getCardNum(tb[i+1][1])+1 then
			return false			
		end
	end		
	if next(tb) and #tb > 1 then 
		return true
	end
	return false
end



--3带一对
function Rule:isSanDaiYiDui(tbCard)
	local len = #tbCard
	if len ~= 5 then
		return false
	end
	self:sortCards(tbCard)
	local num1,num2,num3
	local tbSub = {}
	local bDuiZi = false
	for i=1,len-2 do 
		num1 = self:getCardNum(tbCard[i])
		num2 = self:getCardNum(tbCard[i+1])
		num3 = self:getCardNum(tbCard[i+2])
		if num1 == num2 and num1 == num3 then
			if i==1 then 
				tbSub = table.sub(tbCard,3)				
				bDuiZi = self:isDuizi(tbSub)
			else
				tbSub = table.sub(tbCard,1,2)				
				bDuiZi = self:isDuizi(tbSub)				
			end
			if bDuiZi then 
				return true
			end
		end
	end
	return false
end

--炸弹
function Rule:isZhaDan(tbCard)
	local len = #tbCard
	if len ~= 4 then
		return false
	end
	self:sortCards(tbCard)
	local num1 = self:getCardNum(tbCard[1])
	local num2 = self:getCardNum(tbCard[2])
	local num3 = self:getCardNum(tbCard[3])
	local num4 = self:getCardNum(tbCard[4])
	if num1 == num2 and num1 == num3 and num1 == num4 then
		return true
	end	
	return false
end

--王炸
function Rule:isWangZha(tbCard)
	if #tbCard ~= 2 then 
		return false
	end
	if tbCard[1] + tbCard[2] == 160+170 then 
		return true
	end
	return false
end

--三不带
function Rule:isSanZhang(tbCard)
	local len = #tbCard
	if len ~= 3 then 
		return false
	end
	local num1 = self:getCardNum(tbCard[1])
	if num1 == self:getCardNum(tbCard[2]) and num1 == self:getCardNum(tbCard[3]) then 
		return true
	end
	return false
end

--飞机不带
function Rule:isFeiJiBuDai(tbCard)
	local len = #tbCard
	if len < 6 or len%3~=0 then 
		return false
	end
	self:sortCards(tbCard)
    local n = floor(len / 3)
    local tbCardNum = {}
    local tb
    for i=1, n do     	
    	tb = table.sub(tbCard,(i-1)*3+1,(i-1)*3+3)
    	if not self:isSanZhang(tb) then 
    		return false
    	else
    		--如果连续的3张牌是一样的，记录其中一张牌的值 
    		tbCardNum[i] = self:getCardNum(tbCard[(i-1)*3+1])
    	end
    end
    for i=1,n-1 do 
    	if tbCardNum[i] - tbCardNum[i+1] ~= 1 then
    		--牌值不连接
    		print("牌值不连接")
    		return false
    	end
    end	
    return true,tbCardNum[#tbCardNum]
end

--飞机带
function Rule:isFeiJiDai(tbCard)
	local len = #tbCard
	local n = 1 --多少节
	local num1,num2,num3
	local minCard	
	if len < 7 then 
		return false
	end
	-- print("isFeiJiDai___",dump(tbCard))
	local tbSan = self:getAllSame(tbCard,3)
	if #tbSan < 2 then 
		return false
	end
	for i=1,#tbSan-1 do 
		num1 = self:getCardNum(tbSan[i][1])
		num2 = self:getCardNum(tbSan[i+1][1])
		if num1 == num2 + 1 then 
			n = n + 1
			minCard = num2
		end
	end
	if len > n*3+n*2 then 
		return false
	end
	-- print("_____n___",n)
	return true,minCard
end
-- --飞机带
-- function Rule:isFeiJiDai(tbCard)
-- 	local len = #tbCard
-- 	local n = floor(len/4) --
-- 	local num1,num2,num3
-- 	local tb = {}
-- 	local bFeiji = false
-- 	local bLiangDui = false
-- 	local bDanZhang = false
-- 	if len < 8 then 
-- 		return false
-- 	end
-- 	for i=1,len-2,1 do 
-- 		num1 = self:getCardNum(tbCard[i])
-- 		num2 = self:getCardNum(tbCard[i+1])
-- 		num3 = self:getCardNum(tbCard[i+2])
-- 		if num1 == num2 and num1 == num3 then 
-- 			if len - 3*n == n then 
-- 				bDanZhang = true
-- 			end
-- 			--
-- 			if not bDanZhang then 
-- 				local tbSub = table.subRest(tbCard,i,3*n) 
-- 				bLiangDui = true
-- 				local tp
-- 				for j=1,#tbSub,2 do 
-- 					if not self:isDuizi({tbSub[j],tbSub[j+1]}) then 
-- 						bLiangDui = false
-- 					end
-- 				end
-- 			end
-- 			local num 
-- 			local tbSub = table.sub(tbCard,i+3)
-- 			local tbSan = self:getAllSame(tbSub,3)
-- 			local minCard
-- 			table.insert(tb,tbCard[i])
-- 			table.insert(tb,tbCard[i+1])
-- 			table.insert(tb,tbCard[i+2])
-- 			for j=1,n-1 do 
-- 				table.concatList(tb,tbSan[j])
-- 			end
-- 			if floor(#tb/3) ~= n then
-- 				bFeiji = false
-- 			else				
-- 				bFeiji = self:isFeiJiBuDai(tb)
-- 			end
-- 			minCard = tb[#tb]
-- 			-- print("___bDanZhang__",bDanZhang,bLiangDui,bFeiji,minCard)
-- 			if (bDanZhang or bLiangDui) and bFeiji then 
-- 				return true,bDanZhang,minCard
-- 			end
-- 			return false
-- 		end
-- 	end
-- 	return false
-- end

--飞机
function Rule:isFeiJi(tbCard)
	local len = #tbCard
	local flag = false
	local minCard
	if len < 6 then 
		return false
	end
	self:sortCards(tbCard)
	-- print(dump(tbCard))
	flag,minCard = self:isFeiJiBuDai(tbCard)
	if not flag then 
		flag,minCard = self:isFeiJiDai(tbCard)
	end	
	return flag,minCard
end

--3带1
function Rule:isSanDaiYi(tbCard)
	local len = #tbCard
	local num1,num2,num3,num4
	if len ~= 4 then 
		return false
	end
	self:sortCards(tbCard)
	for i=1,2 do 
		num1 = self:getCardNum(tbCard[i])
		num2 = self:getCardNum(tbCard[i+1])
		num3 = self:getCardNum(tbCard[i+2])		
		if num1 == num2 and num1 == num3 then 
			return true,num1
		end
	end
	return false
end

--3带2
function Rule:isSanDaiEr(tbCard)
	local len = #tbCard
	local num1,num2,num3,num4
	if len ~= 5 then 
		return false
	end
	self:sortCards(tbCard)
	for i=1,3 do 
		num1 = self:getCardNum(tbCard[i])
		num2 = self:getCardNum(tbCard[i+1])
		num3 = self:getCardNum(tbCard[i+2])		
		if num1 == num2 and num1 == num3 then 
			return true,num1
		end
	end
	return false
end

--4带n(1-3)
function Rule:isSiDaiN(tbCard)
	local len = #tbCard
	local num1,num2,num3,num4
	if len < 5 or len > 7 then 
		return false
	end
	self:sortCards(tbCard)
	for i=1,len-3 do 
		num1 = self:getCardNum(tbCard[i])
		num2 = self:getCardNum(tbCard[i+1])
		num3 = self:getCardNum(tbCard[i+2])
		num4 = self:getCardNum(tbCard[i+3])
		if num1 == num2 and num1 == num3 and num1 == num4 then 
			return true,num1
		end
	end
	return false
end

--4带2
function Rule:isSiDaiEr(tbCard)
	local len = #tbCard
	local num1,num2,num3,num4
	if len ~= 6 then 
		return false
	end
	self:sortCards(tbCard)
	for i=1,3 do 
		num1 = self:getCardNum(tbCard[i])
		num2 = self:getCardNum(tbCard[i+1])
		num3 = self:getCardNum(tbCard[i+2])
		num4 = self:getCardNum(tbCard[i+3])
		if num1 == num2 and num1 == num3 and num1 == num4 then 
			return true
		end
	end
	return false
end

--顺子
function Rule:isShunZi(tbCard)
	local len = #tbCard
	if len <5 or len > 12 then 
		return false
	end
	-- print(dump(tbCard),"__1111111111____tbCard")
	self:sortCards(tbCard)
	local prevNum,nextNum
	local tbIgnoreCard = {17,16,15}
	for i=1,len-1 do 
		nextNum = self:getCardNum(tbCard[i])
		prevNum = self:getCardNum(tbCard[i+1])
		for k,v in pairs(tbIgnoreCard) do 
			if prevNum == v or nextNum==v then 
				return false
			end
		end		
		if nextNum - prevNum ~= 1 then 
			return false
		end
	end
	return true
end

--取牌型
function Rule:getCardType(tbCard)
	local cardType 
	local res,subType,minCard
	self:sortCards(tbCard)
	-- print("____tbCard__",dump(tbCard))
	if self:isDanZhang(tbCard) then 
		cardType = self.cardType.danZhang
	elseif self:isDuizi(tbCard) then 
		cardType = self.cardType.duiZi
	elseif self:isZhaDan(tbCard) then 
		cardType = self.cardType.zhaDan
	elseif self:isSanZhang(tbCard) then 
		cardType = self.cardType.sanZhang
	end
	if cardType then 
		-- print("cardType___",cardType)
		return cardType
	end	
	res,minCard = self:isSiDaiN(tbCard)
	if res then 
		cardType = self.cardType.siDaiN	
		-- print("cardType___",cardType)
		return cardType,minCard	
	end			
	res,minCard = self:isSanDaiEr(tbCard)
	if res then 
		cardType = self.cardType.sanDaiEr	
		-- print("cardType___",cardType)
		return cardType,minCard	
	end		
	res,minCard = self:isSanDaiYi(tbCard)
	if res then 
		cardType = self.cardType.sanDaiYi	
		-- print("cardType___",cardType)
		return cardType,minCard	
	end			
	if self:isLiangDui(tbCard) then 
		cardType = self.cardType.liangDui
	elseif self:isShunZi(tbCard) then 
		cardType = self.cardType.shunZi
	end
	if cardType then 
		-- print("cardType___",cardType)
		return cardType
	end	
	res,minCard = self:isFeiJi(tbCard)
	if res then 
		cardType = self.cardType.feiJi
		-- print("cardType___",cardType)
		return cardType,minCard		
	end	
	if not cardType then 
		-- print("牌型不存在",dump(tbCard))
	end
	return cardType								
end

--比较单张牌
function Rule:compareDanZhang(card1,card2)
	local num1 = self:getCardNum(card1)
	local num2 = self:getCardNum(card2)
	if num1 > num2 then 
		return true
	elseif num1 < num2 then 
		return false
	end
	--花色大小
	local color1 = self:getCardColor(card1)
	local color2 = self:getCardColor(card2)
	if color1 > color2 then 
		return true
	end
	return false
end

--比较手牌 
--tbCard1 > tbCard2 返回true
function Rule:compareCards(tbCard1, tbCard2, cardType1, cardType2)
	if not tbCard1 or not next(tbCard1) then 
		return false
	end
 	if not tbCard2 or not next(tbCard2) then
 		return true
 	end
 	local minCard1,minCard2
 	if not cardType1 then 
		cardType1,minCard1 = self:getCardType(tbCard1)
	end
	if not cardType2 then 
		cardType2,minCard2 = self:getCardType(tbCard2)
	end
	local cardType = self.cardType
	local len1 = #tbCard1
	local len2 = #tbCard2
    --集中判断对方不是炸弹，我出炸弹的情况
    if cardType2 ~= cardType.zhaDan and cardType1 == cardType.zhaDan then
        return true
    elseif cardType2 == cardType.zhaDan and cardType1 ~= cardType.zhaDan then
    	return false
    end
    self:sortCards(tbCard1)
    self:sortCards(tbCard2)
        
    local bCompareNum = self:compareDanZhang(tbCard1[1],tbCard2[1])
	-- print("____cardType1___",cardType1,cardType2,minCard1,minCard2)
	if  cardType2 ~= cardType1 then 
		return false
	end
	if len1 ~= len2 then 
		return false
	end	
	for k,v in pairs(self.cardType) do 
		if cardType1 == v then
			if v == cardType.sanDaiYi or v == cardType.sanDaiEr or v == cardType.feiJi or v == cardType.siDaiN then 
				return minCard1>minCard2 
			else
				return bCompareNum		
			end
		end
	end
end

--别人出牌我的手牌里有没有能管住他的牌
function Rule:getBiggerCard(tbMyCard,tbOtherCard,otherCardType)
	if not otherCardType then 
		otherCardType = self:getCardType(tbOtherCard)
	end
	local cardType = self.cardType
	local myLen = #tbMyCard	
	local tbZd = {} 
	local tbResCards = {} --所有结果
	local tb
	if not otherCardType then 
		--牌型不存在
		print("tbOtherCard牌型不存在",tbOtherCard)
		return false
	end
	self:printCardType(otherCardType)
	-- if otherCardType == cardType.wangZha then 
	-- 	--跑得快没有王
	-- 	return false
	-- end
	self:sortCards(tbMyCard)
	self:sortCards(tbOtherCard)
	if otherCardType ~= cardType.zhaDan and myLen>=4 then 	
		--炸弹
		tbZd = self:getZhaDan(tbMyCard)
		if tbZd and next(tbZd) then 
			table.concatList(tbResCards,tbZd)
		end
	end
	if otherCardType == cardType.danZhang then 
		--单张
		tb = self:getDanZhang(tbMyCard,tbOtherCard)
	elseif otherCardType == cardType.duiZi then 
		--对子
		tb = self:getDuiZi(tbMyCard,tbOtherCard)	
	elseif otherCardType == cardType.sanZhang then 
		--3张
		tb = self:getSanZhang(tbMyCard,tbOtherCard)	
	elseif otherCardType == cardType.sanDaiYi then 
		tb = self:getSanDaiYi(tbMyCard,tbOtherCard)		
	elseif otherCardType == cardType.sanDaiEr then 
		--3带2
		tb = self:getSanDaiEr(tbMyCard,tbOtherCard)
	elseif otherCardType == cardType.zhaDan then 	
		--炸弹
		tb = self:getZhaDan(tbMyCard,tbOtherCard)	
	elseif otherCardType == cardType.shunZi then 	
		--顺子
		tb = self:getShunzi(tbMyCard,tbOtherCard)
	elseif otherCardType == cardType.liangDui then
		--连对
		tb = self:getLiangDui(tbMyCard,tbOtherCard)
	elseif otherCardType == cardType.feiJi  then
		--飞机
		tb = self:getFeiji(tbMyCard,tbOtherCard)
	end	
	-- print("_________tb____",dump(tb))
	if tb and next(tb) then 
		table.concatList(tbResCards,tb)
	end
	return tbResCards
end

--取飞机
function Rule:getFeiji(tbMyCard,tbOtherCard,otherLen)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 6 then 
		return false
	end		
	local otherCardNum1 = 0 --最小节牌
	local cardType,js
	if tbOtherCard then
		otherLen = #tbOtherCard
		if otherLen < 6 then return false end 
		-- otherCardNum1 = self:getCardNum(tbOtherCard[4])
		cardType,otherCardNum1,js = self:getCardType(tbOtherCard)
		print("____otherCardNum1____",otherCardNum1)
	end	
	local cards = {}
	local type1,minCard
	for i=myLen,otherLen,-1 do 
		cards = {}
		for j=1,otherLen do 
			table.insert(cards,tbMyCard[i-j+1])
		end
		type1,minCard = self:getCardType(cards)
		if type1 == self.cardType.feiJi then 
			--取到飞机部分
			if minCard > otherCardNum1 then 
				table.insert(tbResCards,cards)
			end
		end
	end		
	return tbResCards
end

--取连对
function Rule:getLiangDui(tbMyCard,tbOtherCard,otherLen)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 4 then 
		return false
	end		
	local otherCardNum1 = 0
	if not otherLen then 
		otherLen = 4
	end
	if tbOtherCard then
		otherLen = #tbOtherCard
		if otherLen < 4 then return false end 
		otherCardNum1 = self:getCardNum(tbOtherCard[1])
	end		
	if myLen < otherLen then 
		return false
	end	
	local cards = {}
	for i=myLen,otherLen,-1 do 
		cards = {}
		for j=1,otherLen do 
			table.insert(cards,tbMyCard[i-j+1])
		end
		local type1 = self:getCardType(cards)
		if type1 == self.cardType.liangDui then 
			if self:getCardNum(cards[1]) > otherCardNum1 then 
				table.insert(tbResCards,cards)
			end
		end
	end
	return tbResCards
end

--取顺子
function Rule:getShunzi(tbMyCard,tbOtherCard,otherLen)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 5 then 
		return false
	end		
	local otherCardNum1 = 0
	if not otherLen then 
		otherLen = 5
	end
	if tbOtherCard then
		otherLen = #tbOtherCard
		if otherLen < 5 then return false end 
		otherCardNum1 = self:getCardNum(tbOtherCard[1])
	end		
	--顺子
	if myLen < otherLen then 
		return false
	end	
	--一样值的牌先过滤
	local num1,num2
	local tbMyCard2 = {}
	for i=1,myLen-1 do 
		if not num1 then 
			num1 = self:getCardNum(tbMyCard[i])
			table.insert(tbMyCard2,tbMyCard[i])
		end
		num2 = self:getCardNum(tbMyCard[i+1])
		if num1 ~= num2 then 
			table.insert(tbMyCard2,tbMyCard[i+1])
			num1 = num2
		end
	end
	local myLen2 = #tbMyCard2
	if myLen2 < otherLen then 
		return false
	end
	local type1
	local cards
	for i=myLen2,otherLen,-1 do 
		cards = {}
		for j=1,otherLen do 
			table.insert(cards,tbMyCard2[i-j+1])
		end			
		type1 = self:getCardType(cards)
		if type1 == self.cardType.shunZi then 
			if self:getCardNum(cards[1]) > otherCardNum1 then 											
				table.insert(tbResCards,cards)
			end
		end
	end	
	return tbResCards
end

--取炸弹
function Rule:getZhaDan(tbMyCard,tbOtherCard)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 4 then 
		return false
	end		
	local otherCardNum1 = 0
	if tbOtherCard then 
		otherCardNum1 = self:getCardNum(tbOtherCard[1])
	end	
	local myNum1,myNum2,myNum3,myNum4
	for i=myLen,4,-1 do 
		myNum1 = self:getCardNum(tbMyCard[i])
		myNum2 = self:getCardNum(tbMyCard[i-1])
		myNum3 = self:getCardNum(tbMyCard[i-2])
		myNum4 = self:getCardNum(tbMyCard[i-3])
		if myNum2 == myNum1 and myNum3 == myNum1 and myNum4 == myNum1 then 
			if myNum1 > otherCardNum1 then 				
				resCards = {}
				table.insert(resCards,tbMyCard[i])
				table.insert(resCards,tbMyCard[i-1])
				table.insert(resCards,tbMyCard[i-2])	
				table.insert(resCards,tbMyCard[i-3])	
				table.insert(tbResCards,resCards)			
			end
		end
	end		
	return tbResCards
end

--取单张
function Rule:getDanZhang(tbMyCard,tbOtherCard)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 1 then 
		return false
	end		
	local otherCardNum1 = 0
	if tbOtherCard then 
		otherCardNum1 = self:getCardNum(tbOtherCard[1])
	end	
	for k,v in pairs(tbMyCard) do 
		if self:getCardNum(v) > otherCardNum1 then 
			resCards = {}
			table.insert(resCards,v)
			table.insert(tbResCards,resCards)
		end
	end
	return tbResCards
end

--取对子
function Rule:getDuiZi(tbMyCard,tbOtherCard)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 2 then 
		return false
	end		
	self:sortCards(tbMyCard)
	local otherCardNum1 = 0
	if tbOtherCard then 
		otherCardNum1 = self:getCardNum(tbOtherCard[1])
	end	
	local myNum1,myNum2
	for i=myLen,2,-1 do 
		myNum1 = self:getCardNum(tbMyCard[i])
		myNum2 = self:getCardNum(tbMyCard[i-1])								
		if myNum2 == myNum1 then
			if myNum1 > otherCardNum1 then  
				resCards = {}
				table.insert(resCards,tbMyCard[i])
				table.insert(resCards,tbMyCard[i-1])
				table.insert(tbResCards,resCards)
			end
		end
	end	
	return tbResCards
end

--取3张
function Rule:getSanZhang(tbMyCard,tbOtherCard)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 3 then 
		return false
	end	
	local otherCardNum1 = 0
	if tbOtherCard then 
		otherCardNum1 = self:getCardNum(tbOtherCard[1])
	end	
	local myNum1,myNum2,myNum3
	for i=myLen,3,-1 do 
		myNum1 = self:getCardNum(tbMyCard[i])
		myNum2 = self:getCardNum(tbMyCard[i-1])
		myNum3 = self:getCardNum(tbMyCard[i-2])
		if myNum2 == myNum1 and myNum3 == myNum1 then 
			if myNum1 > otherCardNum1 then
				resCards = {}
				table.insert(resCards,tbMyCard[i])
				table.insert(resCards,tbMyCard[i-1])
				table.insert(resCards,tbMyCard[i-2])
				table.insert(tbResCards,resCards)				
			end
		end
	end		
	return tbResCards
end

--取3带1的牌
function Rule:getSanDaiYi(tbMyCard,tbOtherCard)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 4 then 
		return false
	end
	local otherCardNum1 = 0
	if tbOtherCard then 
		otherCardNum1 = self:getCardNum(tbOtherCard[3])
	end	
	local myNum1,myNum2,myNum3
	local restCard
	local tbDanPai 
	for i=myLen,3,-1 do 
		myNum1 = self:getCardNum(tbMyCard[i])
		myNum2 = self:getCardNum(tbMyCard[i-1])
		myNum3 = self:getCardNum(tbMyCard[i-2])
		if myNum2 == myNum1 and myNum3 == myNum1 then 	
			if myNum1 > otherCardNum1 then 			
				resCards = {}
				table.insert(resCards,tbMyCard[i])
				table.insert(resCards,tbMyCard[i-1])
				table.insert(resCards,tbMyCard[i-2])
				--从所有单牌中取出2张小的牌
				restCard = table.subRest(tbMyCard,i-2,3)
				tbDanPai = self:getDanPai(restCard,myNum1)
				table.insert(resCards,tbDanPai[1])
				table.insert(tbResCards,resCards)		
			end	
		end
	end		
	return tbResCards
end

--取3带2的牌
function Rule:getSanDaiEr(tbMyCard,tbOtherCard)
	local tbResCards = {}
	local resCards = {}
	local myLen = #tbMyCard
	if myLen < 5 then 
		return false
	end
	local otherCardNum1 = 0
	if tbOtherCard then 
		otherCardNum1 = self:getCardNum(tbOtherCard[3])
	end	
	local myNum1,myNum2,myNum3
	local restCard
	local tbDanPai 
	for i=myLen,3,-1 do 
		myNum1 = self:getCardNum(tbMyCard[i])
		myNum2 = self:getCardNum(tbMyCard[i-1])
		myNum3 = self:getCardNum(tbMyCard[i-2])
		if myNum2 == myNum1 and myNum3 == myNum1 then 	
			-- print(myNum1,"____111")
			if myNum1 > otherCardNum1 then 			
				resCards = {}
				table.insert(resCards,tbMyCard[i])
				table.insert(resCards,tbMyCard[i-1])
				table.insert(resCards,tbMyCard[i-2])
				--从所有单牌中取出2张小的牌
				restCard = table.subRest(tbMyCard,i-2,3)
				tbDanPai = self:getDanPai(restCard,myNum1)
				table.insert(resCards,tbDanPai[1])
				table.insert(resCards,tbDanPai[2])
				table.insert(tbResCards,resCards)		
			end	
		end
	end		
	return tbResCards
end

--从手牌中选出一个牌型
function Rule:getCardByType(tbMyCard,myCardType)
	local tbCard 
	local tbCardScr = table.clone(tbMyCard)
	local tbZha
	self:sortCards(tbCardScr)
	for num=#tbCardScr,6,-1 do 
		tbCard = self:getFeiji(tbCardScr,nil,num)
		if tbCard and next(tbCard) then 
			return tbCard[1]
		end
	end
	tbZha = self:getZhaDan(tbCardScr)
	if tbZha and next(tbZha) then 
		tbCardScr = table.removeSub(tbCardScr,tbZha[1])
	end	

	tbCard = self:getSanDaiEr(tbCardScr)
	if tbCard and next(tbCard) then 
		return tbCard[1]
	end	
	for num=16,4,-2 do 
		-- print("___num__",num)
		tbCard = self:getLiangDui(tbCardScr,nil,num)
		if tbCard and next(tbCard) then 
			return tbCard[1]
		end		
	end
	tbCard = self:getSanDaiYi(tbCardScr)
	if tbCard and next(tbCard) then 
		return tbCard[1]
	end		
	for num=16,5,-1 do 
		tbCard = self:getShunzi(tbCardScr,nil,num)
		if tbCard and next(tbCard) then 
			return tbCard[1]
		end	
	end

	tbCard = self:getSanZhang(tbCardScr)
	if tbCard and next(tbCard) then 
		return tbCard[1]
	end		
	tbCard = self:getDuiZi(tbCardScr)
	if tbCard and next(tbCard) then 
		return tbCard[1]
	end			
	tbCard = self:getDanZhang(tbCardScr)
	if tbCard and next(tbCard) then 
		return tbCard[1]
	end		
	if tbZha and tbZha[1] then 
		return tbZha[1]
	end		
end

--指定的牌是否在手牌中是n条
function Rule:cardIsLiang(card,tbCard,n)
	local cardNum = self:getCardNum(card)
	local num = 0
	if not n then 
		n = 2
	end
	for k,v in pairs(tbCard) do 
		if cardNum == self:getCardNum(v) then 
			num = num + 1
		end
	end
	if num >= n then
		return true
	end
	return false
end

--取手中的单牌,ignoreCard放在最后
function Rule:getDanPai(tbMyCard,ignoreCardNum)
	local tbLiang = {}
	local tbDan = {}
	local tbIgnore = {}
	local tbShunzi = {}
	local tbCard = tbMyCard

	for j=1,#tbCard do 
		if self:getCardNum(tbCard[j]) ~= ignoreCardNum then 
			if self:cardIsLiang(tbCard[j],tbCard,2) then
				table.insert(tbLiang,tbCard[j])
			else
				table.insert(tbDan,tbCard[j])
			end
		else
			table.insert(tbIgnore,tbCard[j])
		end
	end
	for num=16,5,-1 do 
		tbCard = self:getShunzi(tbDan,nil,num)
		if tbCard and next(tbCard) then 
			tbShunzi = tbCard[1]
			break
		end	
	end
	if next(tbShunzi) then 
		tbDan = table.removeSub(tbDan,tbShunzi)
	end

	table.sort(tbDan)
	for i=#tbLiang,1,-1 do 
		table.insert(tbDan,tbLiang[i])
	end
	for i=#tbIgnore,1,-1 do 
		table.insert(tbDan,tbIgnore[i])
	end
	for i=#tbShunzi,1,-1 do 
		table.insert(tbDan,tbShunzi[i])
	end	
	return tbDan
end

--拆牌
-- 单张 1
-- 对子 2
-- 三带 3
-- 连牌 4 (每多一张牌权值+1)
-- 连对 5（每多一对牌，权值+2）
-- 飞机 6（每对以飞机，权值在基础上+3）
-- 炸弹 7（包括对王在内）
-- function Rule:sliptCard(tbMyCard)
-- 	local tbValue = {
-- 		[self.cardType.danZhang] = 1,
-- 		[self.cardType.duiZi] = 2,
-- 		[self.cardType.sanZhang] = 3,
-- 		[self.cardType.shunZi] = 4,
-- 		[self.cardType.liangDui] = 5,
-- 		[self.cardType.feiJi] = 6,
-- 		[self.cardType.zhaDan] = 8,
-- 	}
-- 	local function getValue(cardType,cardNum)
-- 		local value = tbValue[cardType]
-- 		if cardType == self.cardType.shunZi then 
-- 			value = value + (cardNum-4)
-- 		elseif cardType == self.cardType.liangDui then 
-- 			value = value + (cardNum/2 - 2)*2
-- 		elseif cardType == self.cardType.feiJi then 
-- 			value = value + (cardNum - 5)
-- 		elseif cardType == self.cardType.zhaDan then 
-- 			value = value
-- 		end
-- 	end
-- 	--先选出独立的 3条，2条，
-- 	--1张牌是否能与别的牌组成顺子，连对，飞机
-- 	local tbCard = table.copy(tbMyCard)
-- 	self:sortCards(tbCard)
-- 	local st = self:getAllSame(tbCard,3)
	
-- 	local tbCard1 = table.removeSub(tbCard,st)
-- 	print("___tbCard1__",dump(tbCard1))	
-- 	local sd = self:getAllSame(tbCard1,2)

-- 	print("___st__",dump(st))
-- 	print("___sd__",dump(sd))

-- end

--牌型基础权值
function Rule:getTypeValue(cardType)
	local tbValue = {
		[self.cardType.danZhang]=1,
		[self.cardType.duiZi]=2,
		[self.cardType.siDaiN]=3,
		[self.cardType.sanZhang]=4,
		[self.cardType.sanDaiYi]=5,
		[self.cardType.sanDaiEr]=6,
		[self.cardType.shunZi]=7,
		[self.cardType.liangDui]=8,
		[self.cardType.feiJi]=9,
		[self.cardType.zhaDan]=10,
	}
	return tbValue[cardType]
end

--手牌对应的权值
function Rule:getCardsValue(cards)
	local cardType = self:getCardType(cards)	
	local value = self:getTypeValue(cardType)	
	if cardType == self.cardType.shunZi then 
		value = value + (#cards-5)
	elseif cardType == self.cardType.liangDui then 
		value = value + (math.floor(#cards/2)-2)*2
	elseif cardType == self.cardType.feiJi then 
		value = value + (math.floor(#cards/3) -2)*3		
	elseif cardType == self.cardType.danZhang then 	
		if self:getCardNum(cards[1]) > 12 then 
			value = value + 2
		elseif self:getCardNum(cards[1]) > 9 then 
			value = value + 1
		end
	elseif cardType == self.cardType.duiZi then 
		if self:getCardNum(cards[1]) > 10 then 
			value = value + 1
		end
	end
	-- print("_____getCardsValue___",value)
	return value
end

--拆牌剩余手牌数
function Rule:getCardsHand(cards)
	local tb = {}
	local function getHand(cards)
		local tbCard = self:getCardByType(cards)
		if tbCard and next(tbCard) then 
			table.insert(tb,tbCard)
			tbCard = table.removeSub(cards,tbCard)
			return getHand(tbCard)
		end
		return nil
	end
	getHand(cards)
	-- print("____slipt__",dump(tb))
	return tb
end

function Rule:getRestCardValue(cards)
	local tb = self:getCardsHand(cards)
	local value = 0
	if #cards == 0 then 
		print("___no rest card__")
		return 100
	end
	for k,v in pairs(tb) do 
		value = value + self:getCardsValue(v)
	end
	-- print("___getRestCardValue___",dump(cards),value - (#tb*2),#tb )
	return value - (#tb*2) -- #cards
end


--从手牌中选出一个牌型
function Rule:putHandCard(tbMyCard)
	local tbCard 
	local tbCardScr = table.clone(tbMyCard)
	local tbZha
	local putCard
	local putCardValue
	local restCard={}
	local restCardTemp={}
	local restCardValue
	local maxRestCardValue 
	local tbRecord = {}
	local function func(tbCard,tbCardScr)
		if not tbCard or not next(tbCard) then 
			return
		end
		for k,v in pairs(tbCard) do 
			restCardTemp = table.removeSub(tbCardScr,v)		
			putCardValue = self:getCardsValue(v)	
			restCardValue = self:getRestCardValue(restCardTemp) + putCardValue
			-- print("__putCardValue__restCardValue____",putCardValue,self:getRestCardValue(restCardTemp))
			-- print("____restCardValue__",restCardValue)
			table.insert(tbRecord,{
				putCard=v,
				restCard=restCardTemp,
				value=restCardValue,
				})
		end		
	end
	self:sortCards(tbCardScr)

	for num=#tbCardScr,6,-1 do 
		tbCard = self:getFeiji(tbCardScr,nil,num)
		func(tbCard,tbCardScr)
	end
	-- print(dump(tbRecord))
	print("_____________tbRecord___")
	tbZha = self:getZhaDan(tbCardScr)
	func(tbCard,tbCardScr)	

	tbCard = self:getSanDaiEr(tbCardScr)
	func(tbCard,tbCardScr)	

	for num=16,4,-2 do
		tbCard = self:getLiangDui(tbCardScr,nil,num)
		func(tbCard,tbCardScr)	
	end
	tbCard = self:getSanDaiYi(tbCardScr)
	func(tbCard,tbCardScr)	

	for num=16,5,-1 do 
		tbCard = self:getShunzi(tbCardScr,nil,num)
		func(tbCard,tbCardScr)	
	end
	tbCard = self:getSanZhang(tbCardScr)
	func(tbCard,tbCardScr)		
	tbCard = self:getDuiZi(tbCardScr)
	func(tbCard,tbCardScr)				
	tbCard = self:getDanZhang(tbCardScr)
	func(tbCard,tbCardScr)		
	-- if tbZha and tbZha[1] then 
	-- 	return tbZha[1]
	-- end		
	-- print("putCard__",dump(putCard),maxRestCardValue,dump(restCard))
	local function sortFunc(a,b)
		if a.value>b.value then 
			return true
		elseif a.value==b.value then 
			return #a.restCard < #b.restCard
		end
		return false
	end
	table.sort(tbRecord,sortFunc)
	-- print(dump(tbRecord))
	return tbRecord
end

--被动出牌
function Rule:passivePut(tbMyCard,otherCards)
	local tbRes = self:getBiggerCard(tbMyCard,otherCards)	
	local tbRecord = {}
	local restCard
	local value
	local putCardValue
	for k,v in pairs(tbRes) do 
		restCard = table.removeSub(tbMyCard,v)	
		putCardValue = self:getCardsValue(v)	
		value = self:getRestCardValue(restCard) + putCardValue					
		table.insert(tbRecord,{
			putCard=v,
			restCard=restCard,
			value=value,
			})		
	end
	local function sortFunc(a,b)
		if a.value>b.value then 
			return true
		elseif a.value==b.value then 
			return #a.restCard < #b.restCard
		end
		return false
	end
	-- print(dump(tbRecord))
	table.sort(tbRecord,sortFunc)
	return tbRecord	
end

local rule = Rule.new()

-- --连对
-- local tbCard = {31,32,21,22,52,51}
-- local res = rule:isLiangDui(tbCard)
-- --3带1
-- local tbCard = {31,32,23,33}
-- local res = rule:isSanDaiYi(tbCard)
-- --炸
-- local tbCard = {31,32,34,33}
-- local res = rule:isZhaDan(tbCard)
-- --3不带
-- local tbCard = {31,32,34}
-- local res = rule:isSanZhang(tbCard)
--飞机
-- local tbCard = {42,44,52,54,82,84,82,72,74,72}
-- local res = rule:isFeiJi(tbCard)
-- print(res)
-- -- 3带2
-- local tbCard = {51,32,34,23,31}
-- local res = rule:isSanDaiEr(tbCard)
-- print(res)
-- --3带对
-- local tbCard = {31,32,34,53,51}
-- local res = rule:isSanDaiYiDui(tbCard)
-- --4带2
local tbCard = {	}
-- local res = rule:isSiDaiEr(tbCard)
-- --顺子
-- local tbCard = {31,51,41,61,71}
-- local res = rule:isShunZi(tbCard)

-- --测试
-- local tbMyCard = {82,81,71,72,52,51,61,62} 
-- local tbOtherCard ={43,44,54,53,64,63,73,74}
-- local res = rule:compareCards(tbMyCard,tbOtherCard)
-- print(res)

local tbMyCard = {
	[1]  = 154,
	[2]  = 133,
	[3]  = 131,
	[4]  = 114,
	[5]  = 112,
	[6]  = 111,
	[7]  = 104,
	[8]  = 101,
	[9]  = 44,
	[10] = 43,
}

rule:sortCards(tbMyCard)
local tbOtherCard ={
	[1] = 113,
	[2] = 94,
	[3] = 93,
	[4] = 91,
	[5] = 74,}
-- local res = rule:getCardType(tbMyCard)
-- local res = rule:getCardCode(tbMyCard)
-- local res = rule:getBiggerCard(tbMyCard,tbOtherCard)
-- local res = rule:getAllSame(tbMyCard,3)
-- local  res = rule:getCardByType(tbMyCard)
-- local res = rule:compareCards(tbMyCard,tbOtherCard)
-- local res = rule:getDanPai(tbMyCard)
-- local res = rule:getSanDaiEr(tbMyCard)
-- local res = rule:getCardType(tbMyCard)
-- local res = rule:sliptCard(tbMyCard)
-- local res = rule:getCardsValue(tbMyCard)
-- local res = rule:getCardsHand(tbMyCard)


-- local res = rule:getRestCardValue(tbMyCard)
-- local res = rule:putHandCard(tbMyCard)
-- local res = rule:passivePut(tbMyCard,tbOtherCard)

print("结果",dump(res))

-- local date = os.date("%Y%m%d", os.time())
-- print("___date___",date)
-- print(os.time())

return Rule